package dicky.fortunetelling.logic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import dicky.fortunetelling.R;
import dicky.fortunetelling.R.id;
import dicky.fortunetelling.R.layout;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class GoodNumberDlg extends Dialog {
    
    private Context context;
    private ListView listview;
    private List list;

    
    public GoodNumberDlg(Context context,List list) {
        super(context);
        this.context = context;
        this.list=list;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置对话框使用的布局文件
        this.setContentView(R.layout.goodnumber);

        listview = (ListView) findViewById(R.id.listview);

        // 设置ListView的数据源
        SimpleAdapter adapter = new SimpleAdapter(context, getList(list),
                R.layout.goodnumberlist, null,null);
        listview.setAdapter(adapter);

    }

    /**
     * 得到ListView数据源
     * 
     * @return
     */
    private List<HashMap<String, Object>> getList(List list) {
        List<HashMap<String, Object>> priorityList = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> map=null;
        HashMap listmap=null;
        String str="";
        for (int i=0;i<list.size();i++){
        	map = new HashMap<String, Object>();
        	listmap=(HashMap)list.get(i);
        	map.put("c", listmap.get("num")+"");
        	str=listmap.get("text1")+"\n\n"+listmap.get("text2");
        	map.put("text1", str);
        	priorityList.add(map);
        }

        return priorityList;
    }
}
